/**
 * CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

package com.cmcc.zysoft.infocollection.mobile.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.cmcc.zysoft.infocollection.mobile.dao.MResourcePropertyDao;
import com.cmcc.zysoft.infocollection.model.ResourceProperty;
import com.starit.common.dao.hibernate.HibernateBaseDao;
import com.starit.common.dao.service.BaseServiceImpl;

/**
 * @author 袁凤建
 * <br />邮箱: yuan.fengjian@ustcinfo.com
 * <br />描述: ResourcePropertyService.java
 * <br />版本: 1.0.0
 * <br />日期: 2013-8-8 下午5:27:50
 * <br />CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

@Service
public class MResourcePropertyService extends BaseServiceImpl<ResourceProperty, String> {

	@Resource
	private MResourcePropertyDao mResourcePropertyDao;
	
	/**
	 * 属性名称: mIndustryService.
	 * 类       型: MIndustryService.
	 */
	@Resource
	private MIndustryService mIndustryService;
	
	@Override
	public HibernateBaseDao<ResourceProperty, String> getHibernateBaseDao() {
		return this.mResourcePropertyDao;
	}
	
	/**
	 * 模板字段是否必填接口-通过该接口，可以返回行业模板中的字段是否为必填.
	 * @param industryId 行业ID
	 * @return map
	 */
	public Map<String, Object> getTemplate(String industryId) {
		Map<String, Object> map = new HashMap<String, Object>();
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<Map<String, Object>> industryList = this.mIndustryService.getIndustryById(industryId);
		if(!industryList.isEmpty()) {
			String propertyCode = "";
			String propertyFlag = "";
			List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
			List<Map<String, Object>> list = this.mResourcePropertyDao.getTemplate(industryId);
			if(!list.isEmpty()) {
				for(Map<String, Object> listMap : list) {
					propertyCode = listMap.get("resource_property_enname").toString();
					propertyFlag = listMap.get("resource_property_flag").toString();
					map.put(propertyCode, propertyFlag);
				}
				resultList.add(map);
				resultMap.put("status", "1");
				resultMap.put("result", resultList);
			} else {
				resultMap.put("status", "2");
				resultMap.put("message", "暂无模板数据");
			}
		} else {
			resultMap.put("status", "2");
			resultMap.put("message", "暂无该行业,请确认");
		}
		return resultMap;
	}
	
	/**
	 * 根据行业ID获取该行业下模板字段的是否必填信息.
	 * @param industryId 行业ID
	 * @return map
	 */
	public Map<String, Object> getProperty(String industryId) {
		String propertyCode = "";
		String propertyFlag = "";
		Map<String, Object> map = new HashMap<String, Object>();
		List<Map<String, Object>> list = this.mResourcePropertyDao.getTemplate(industryId);
		if(!list.isEmpty()) {
			for(Map<String, Object> listMap : list) {
				propertyCode = listMap.get("resource_property_enname").toString();
				propertyFlag = listMap.get("resource_property_flag").toString();
				map.put(propertyCode, propertyFlag);
			}
		}
		return map;
	}
}